//package com.czkt.config;
//
//import at.pollux.thymeleaf.shiro.dialect.ShiroDialect;
//import com.czkt.service.ISysRoleService;
//import org.apache.shiro.mgt.SecurityManager;
//import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
//import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
//import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
//import org.crazycake.shiro.RedisCacheManager;
//import org.crazycake.shiro.RedisManager;
//import org.crazycake.shiro.RedisSessionDAO;
//import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//import javax.annotation.Resource;
//
//@Configuration
//public class ShiroConfig {
//    @Value("${spring.redis.host}")
//    private String host;
//
//    @Value("${spring.redis.port}")
//    private int port;
//
//    @Value("${spring.redis.password}")
//    private String password;
//
//    @Value("${spring.redis.timeout}")
//    private int timeout;
//
//    @Resource
//    private ISysRoleService sysRoleService;
//
//    @Bean(name = "shiroDialect")
//    public ShiroDialect shiroDialect(){
//        return new ShiroDialect();
//    }
//
//    @Bean
//    public DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator(){
//        DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator();
//        advisorAutoProxyCreator.setProxyTargetClass(true);
//        return advisorAutoProxyCreator;
//    }
//
//    @Bean
//    public MyShiroRealm myShiroRealm(){//自定义Realm
//        return new MyShiroRealm();
//    }
//
//    @Bean
//    public SecurityManager securityManager(){//安全管理器SecurityManager
//        DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
//        //注入Realm
//        securityManager.setRealm(myShiroRealm());
//        return securityManager;
//    }
//
//    /**
//     * 开启app注解支持
//     */
//    @Bean
//    public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(SecurityManager securityManager){
//        AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor();
//        authorizationAttributeSourceAdvisor.setSecurityManager(securityManager);
//        return authorizationAttributeSourceAdvisor;
//    }
//
//    public RedisManager redisManager(){
//        RedisManager redisManager = new RedisManager();
//        redisManager.setHost(host);
//        redisManager.setPort(port);
//        redisManager.setPassword(password);
//        redisManager.setTimeout(timeout);
//        return redisManager;
//    }
//
//    public RedisCacheManager cacheManager(){
//        RedisCacheManager cacheManager = new RedisCacheManager();
//        cacheManager.setRedisManager(redisManager());
//        //缓存名称
//        cacheManager.setPrincipalIdFieldName("loginUser");
//        //缓存有效时间
//        cacheManager.setExpire(1800);
//        return cacheManager;
//    }
//
//    //会话操作
//    public RedisSessionDAO redisSessionDAO(){
//        RedisSessionDAO sessionDAO = new RedisSessionDAO();
//        sessionDAO.setRedisManager(redisManager());
//        return sessionDAO;
//    }
//
//    //会话管理
//    public DefaultWebSessionManager sessionManager(){
//        DefaultWebSessionManager sessionManager = new DefaultWebSessionManager();
//        sessionManager.setSessionDAO(redisSessionDAO());
//        return sessionManager;
//    }
////    @Bean
////    public MyShiroRealm myShiroRealm(){
////        MyShiroRealm shiroRealm = new MyShiroRealm();
////        //设置启用缓存，并设置缓存名称
////        shiroRealm.setCachingEnabled(true);
////        shiroRealm.setAuthenticationCacheName("authorizationCache");
////        return shiroRealm;
////    }
//
////    @Bean
////    public SecurityManager securityManager(){
////        DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
////        //注入Realm
////        securityManager.setRealm(myShiroRealm());
////        //注入缓存管理器
////        securityManager.setCacheManager(cacheManager());
////        //注入会话管理器
////        securityManager.setSessionManager(sessionManager());
////        return securityManager;
////    }
//
//}
